package com.yingeo.ai.sdk.demo.goods;

import com.yingeo.ai.sdk.client.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class GoodsDataSource {

    public static List<GoodsBean> dataSource = new ArrayList<>();

    public static List<GoodsBean> queryGoodsWithSearch(String keywords) {
        List<GoodsBean> result = new ArrayList<>();
        if (StringUtils.isEmpty(keywords)) return result;
        keywords = keywords.toLowerCase();
        for (GoodsBean goodsBean : dataSource) {
            String goodsCode = goodsBean.getGoodsCode();
            String pinYinName = goodsBean.getPinYinName();
            String pinYinFirstSpell = goodsBean.getPinYinFirstSpell();

            if (goodsCode.contains(keywords) || pinYinName.contains(keywords) || pinYinFirstSpell.contains(keywords)) {
                result.add(goodsBean);
            }
        }
        return result;
    }

    /**
     * 根据商品编码查询商品
     * @param goodsCode
     * @return
     */
    public static GoodsBean queryGoodsWithCode(String goodsCode) {
        if (StringUtils.isEmpty(goodsCode)) return null;
        for (GoodsBean goodsBean : dataSource) {
            if (goodsCode.equals(goodsBean.getGoodsCode())) {
                return goodsBean;
            }
        }
        return null;
    }

    static {
        dataSource.add(new GoodsBean(
                "1001",
                "山东红富士",
                "https://ai.yingeo.com/profile/upload/2022/09/26/2761663047478_.pic.jpg",
                1250,
                "shandonghongfushi",
                "shhfs"));
        dataSource.add(new GoodsBean(
                "1002",
                "江西夏橙",
                "https://ai.yingeo.com/profile/upload/2023/01/24/hjc.jpg",
                1600,
                "jiangxixiacheng",
                "jxxc"));
        dataSource.add(new GoodsBean(
                "1003",
                "新鲜土豆",
                "https://ai.yingeo.com/profile/upload/2022/09/26/2791662905153_.pic.jpg",
                699,
                "xinxiantudou",
                "xxtd"));
        dataSource.add(new GoodsBean(
                "1004",
                "红尖椒",
                "https://ai.yingeo.com/profile/upload/2022/09/27/3071663436766_.pic.jpg",
                1260,
                "hongjianjiao",
                "hjj"));
        dataSource.add(new GoodsBean(
                "1005",
                "精选老姜",
                "https://ai.yingeo.com/profile/upload/2022/09/28/0abef1ad50d5c397.jpg",
                580,
                "jingxuanlaojiang",
                "jxlj"));
        dataSource.add(new GoodsBean(
                "1006",
                "青苹果",
                "https://ai.yingeo.com/profile/upload/2022/09/26/017.jpg",
                1500,
                "qingpingguo",
                "qpg"));
        dataSource.add(new GoodsBean(
                "1007",
                "芒果",
                "https://ai.yingeo.com/profile/upload/2022/10/05/2.jpg",
                2500,
                "mangguo",
                "mg"));
        dataSource.add(new GoodsBean(
                "1008",
                "海南香蕉",
                "https://ai.yingeo.com/profile/upload/2022/09/28/11c7531ff57eee89.jpg",
                980,
                "hainanxiangjiao",
                "hnxj"));
        dataSource.add(new GoodsBean(
                "1009",
                "红心火龙果",
                "https://ai.yingeo.com/profile/upload/2022/09/28/bad32de50d24d3b3.jpg",
                1450,
                "hongxinhuolongguo",
                "hxhlg"));
        dataSource.add(new GoodsBean(
                "1010",
                "砂糖橘",
                "https://ai.yingeo.com/profile/upload/2022/09/28/8781de76f433cb81.jpg",
                500,
                "shatangju",
                "stj"));
        dataSource.add(new GoodsBean(
                "2001",
                "凉拌黄瓜",
                "https://ai.yingeo.com/profile/upload/2023/06/12/lbhg.jpg",
                20,
                "liangbanhuanggua",
                "lbhg"));
        dataSource.add(new GoodsBean(
                "2002",
                "凉拌鸡脚",
                "https://ai.yingeo.com/profile/upload/2023/06/12/lbjz.jpg",
                30,
                "liangbanjijiao",
                "lbjj"));
        dataSource.add(new GoodsBean(
                "2003",
                "红烧豆腐",
                "https://ai.yingeo.com/profile/upload/2023/06/12/hsdf.jpg",
                28,
                "hongshaodoufu",
                "hsdf"));
        dataSource.add(new GoodsBean(
                "2004",
                "清炒蚕豆",
                "https://ai.yingeo.com/profile/upload/2023/06/12/qccd.jpg",
                25,
                "qingchaocandou",
                "qccd"));
        dataSource.add(new GoodsBean(
                "2005",
                "牛角包",
                "https://ai.yingeo.com/profile/upload/2023/06/14/njb.jpg",
                1200,
                "niujiaobao",
                "njb"));
        dataSource.add(new GoodsBean(
                "2006",
                "泡芙",
                "https://ai.yingeo.com/profile/upload/2023/06/14/pf.jpg",
                300,
                "paofu",
                "pf"));
        dataSource.add(new GoodsBean(
                "2007",
                "小餐包",
                "https://ai.yingeo.com/profile/upload/2023/06/14/xcb.jpg",
                300,
                "xiaocanbao",
                "xcb"));
        dataSource.add(new GoodsBean(
                "2008",
                "花朵面包",
                "https://ai.yingeo.com/profile/upload/2023/06/14/hdmb.jpg",
                350,
                "huaduomianbao",
                "hdmb"));
        dataSource.add(new GoodsBean(
                "2009",
                "水果蛋糕",
                "https://ai.yingeo.com/profile/upload/2023/06/14/sgdg.jpg",
                550,
                "shuiguodangao",
                "sgdg"));
        dataSource.add(new GoodsBean(
                "2010",
                "坚果蛋糕",
                "https://ai.yingeo.com/profile/upload/2023/06/14/sgdg.jpg",
                550,
                "jianguodangao",
                "jgdg"));
        dataSource.add(new GoodsBean(
                "2011",
                "农夫山泉矿泉水",
                "https://ai.yingeo.com/profile/upload/2023/06/15/nfsqkqs.jpg",
                550,
                "jianguodangao",
                "nfsqkqs"));
        dataSource.add(new GoodsBean(
                "2012",
                "晨光牛奶红枣味",
                "https://ai.yingeo.com/profile/upload/2023/06/15/cgnn.jpg",
                550,
                "jianguodangao",
                "cgnnhzw"));
        dataSource.add(new GoodsBean(
                "2013",
                "乐事薯片番茄味",
                "https://ai.yingeo.com/profile/upload/2023/06/15/lsmxg.jpg",
                550,
                "jianguodangao",
                "lsspfqw"));
        dataSource.add(new GoodsBean(
                "2014",
                "乐事薯片青瓜味",
                "https://ai.yingeo.com/profile/upload/2023/06/15/lsqgw.jpg",
                550,
                "jianguodangao",
                "lsspqgw"));
        dataSource.add(new GoodsBean(
                "2015",
                "好丽友派",
                "https://ai.yingeo.com/profile/upload/2023/06/15/hlyp.jpg",
                550,
                "jianguodangao",
                "hlyp"));
    }
}
